// 定义接口
interface ParamsType {
    endtime: string,
    wrapper: HTMLElement | null
}

// 封装倒计时
class CountDown {
    endtime: string;  //结束的事件
    wrapper: HTMLElement | null  //要展示的容器
    constructor(params: ParamsType) {
        this.endtime = params.endtime;
        this.wrapper = params.wrapper;
        this.onGoing()
    }
    onGoing() {
        // 定时器进行倒计时
        setInterval(() => {
            const curTime = Date.now();
            const endTime = new Date(this.endtime).getTime()
            const diffTime = endTime - curTime
            const day = new Date(diffTime).getDate();
            const hours = new Date(diffTime).getHours();
            const min = new Date(diffTime).getMinutes();
            const sec = new Date(diffTime).getSeconds();
            (this.wrapper as HTMLElement).innerHTML = `
                ${day}天${hours}时${min}分${sec}秒
            `
        }, 1000)
    }
}

new CountDown({
    endtime: '2022/2/28',
    wrapper: document.getElementById('box')
})